//
//  XWEmptyBaseView.swift
//  XiaoweMiaoYin-Abroad
//
//  Created by edy on 2025/1/8.
//

import UIKit

class XWEmptyBaseView: XWHBaseView {
    
    lazy var titleLb = UILabel()
    lazy var textLb = UILabel()
    lazy var iconView = UIImageView()
    lazy var button = UIButton()
    
    var clickBtnAction: (() -> Void)?

    override func addSubViews() {
        super.addSubViews()
        
        addSubview(titleLb)
        addSubview(textLb)
        addSubview(iconView)
        addSubview(button)
        
        var font = AppFont.harmonyOSSans(ofSize: 27, weight: .bold)
        
        let textColor = majorTextColor
        let textAlignment = NSTextAlignment.center
        
        titleLb.font = font
        titleLb.textColor = textColor
        titleLb.textAlignment = textAlignment
        
        font = AppFont.harmonyOSSans(ofSize: 20, weight: .regular)
        textLb.font = font
        textLb.textColor = textColor
        textLb.textAlignment = textAlignment
        textLb.numberOfLines = 0
        
        config(btn: button)
        button.addTarget(self, action: #selector(clickButton), for: .touchUpInside)
    }
    
    func config(btn: UIButton) {
        let font = AppFont.harmonyOSSans(ofSize: 20, weight: .medium)
        btn.titleLabel?.font = font
        btn.setTitleColor(.white, for: .normal)
        btn.layer.backgroundColor = btnBgColor.cgColor
        btn.layer.cornerRadius = 27
    }
    
    @objc func clickButton() {
        clickBtnAction?()
    }
    
    override func relayoutSubViews() {
        button.snp.makeConstraints { make in
            make.height.equalTo(54)
            make.left.right.equalToSuperview().inset(64)
            make.bottom.equalToSuperview().inset(44)
        }
        titleLb.snp.makeConstraints { make in
            make.height.equalTo(34)
            make.left.right.equalToSuperview().inset(64)
            make.top.equalToSuperview().inset(34)
        }
        iconView.snp.makeConstraints { make in
            make.top.equalTo(titleLb.snp.bottom).offset(24)
            make.size.equalTo(234)
            make.centerX.equalToSuperview()
        }
        
        textLb.snp.makeConstraints { make in
            make.width.centerX.equalTo(titleLb)
            make.height.lessThanOrEqualTo(124)
            make.top.equalTo(iconView.snp.bottom).offset(24)
        }
    }

}
